package cn.tedu.ivos.user.service.impl;

import cn.tedu.ivos.base.exception.UserNotFoundException;
import cn.tedu.ivos.base.response.StatusCode;
import cn.tedu.ivos.user.pojo.dto.UserLoginParam;
import cn.tedu.ivos.user.pojo.vo.UserVO;
import org.springframework.stereotype.Service;

//业务层实现类上要级@Service注解，表示该类是业务层实现类
@Service
public class UserServicelmpl {

    @Override
    public UserVO login(UserLoginParam userLoginParam) {
        log.debug("用户登录业务:userLoginParam={}",userLoginParam);
        Uservo userVO = userMapper.selectByUsername(userLoginParam.getUsername());
        //如果业务层遇到了问题，需要抛出业务层异常，而不是直接给前端响应结构，Controller层会捕获到该异常，然后响应给前端
        if(userVO == null){
            throw new UserNotFoundException(StatusCode.USERNAME_ERROR);
        }else if(!userVO.getPassword().equals(userLoginParam.getPassword())){
            throw new PasswordNotMatchException(StatusCode.PASSWORD_ERROR);
        }
        return userVO;

    }
}
